<template>
  <div class="app-container">
    <el-form ref="form" :model="internship" label-width="150px">
      <el-form-item label="学生名字">
        <el-input v-model="internship.stuName" />
      </el-form-item>
       <el-form-item label="实习单位">
        <el-input v-model="internship.internName" />
      </el-form-item>

      <el-form-item label="实习开始时间">
        <el-date-picker
          v-model="internship.internshipStartTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="实习结束时间">
        <el-date-picker
          v-model="internship.internshipEndTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="实习项目">
        <el-input
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipProject"
        />
      </el-form-item>

      <el-form-item label="实习目的">
        <el-input
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipTarget"
        />
      </el-form-item>

      <el-form-item label="负责内容">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipContent"
        />
      </el-form-item>

      <el-form-item label="负责内容">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipPerformance"
        />
      </el-form-item>

      <el-form-item label="个人总结">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipPersonalSummary"
        />
      </el-form-item>

      <el-form-item label="实习日志第一篇">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipRecordContentOne"
        />
      </el-form-item>

      <el-form-item label="实习日志第二篇">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipRecordContentTwo"
        />
      </el-form-item>

      <el-form-item label="实习日志第三篇">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipRecordContentThree"
        />
      </el-form-item>

      <el-form-item label="实习日志第四篇">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipRecordContentFour"
        />
      </el-form-item>

      <el-form-item label="实习日志完成状态">
        <el-switch
          v-model="internship.internshipRecordStatus"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </el-form-item>

      <el-form-item label="自我鉴定">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipSummaryContent"
        />
      </el-form-item>

      <el-form-item label="实习总结完成状态">
        <el-switch
          v-model="internship.internshipSummaryStatus"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </el-form-item>

      <el-form-item label="指导老师意见">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.teacherOpinion"
        />
      </el-form-item>

      <el-form-item label="指导老师分数">
        <el-input
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.teacherGrade"
        />
      </el-form-item>

      <el-form-item label="实习单位意见">
        <el-input
          type="textarea"
          rows="6"
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipOpinion"
        />
      </el-form-item>

      <el-form-item label="实习单位分数">
        <el-input
          placeholder="请输入内容"
          show-word-limit
          v-model="internship.internshipGrade"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate()">新增</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import recodeApi from "@/api/recode";
export default {
  data() {
    return {
      internship: {
        id: "",
        sid: "",
        internshipStartTime: "",
        internshipEndTime: "",
        internshipRecordContentOne: "",
        internshipRecordContentTwo: "",
        internshipRecordContentThree: "",
        internshipRecordContentFour: "",
        internshipRecordStatus: "",
        internshipSummaryContent: "",
        internshipSummaryStatus: "",
        internshipGrade: "",
      },
    };
  },
  created() {
    // 页面渲染之前执行
    this.init();
  },
  watch: {
    //监听
    $route(to, from) {
      // console.log(to)
      // console.log(from)
      //路由变化方式，路由发生变化，方法就会执行
      this.init();
    },
  },
  methods: {
    init() {
      //判断url路径有id值,做修改
      if (this.$route.params && this.$route.params.id) {
        //从路径获取id值
        const id = this.$route.params.id;
        //调用根据id查询的方法
        this.getInfo(id);
        //
      } else {
        //路径没有id值，做添加
        //清空表单
        this.internship = {};
      }
    },
    //获取实习记录信息
    getInfo(id) {
      recodeApi.getInternshipInfo(id).then((response) => {
        this.internship = response.data.internship;
      });
    },

    saveOrUpdate() {
      //判断修改还是添加
      //根据user是否有id
      if (!this.internship.id) {
        //添加
        this.saveInternship();
      } else {
        //修改
        this.updateInternship();
      }
    },

    saveInternship() {
      recodeApi.addInternship(this.internship).then((resp) => {
        //提示信息
        this.$message({
          type: "success",
          message: "新增成功!",
        });
        //回到列表页面 路由跳转
        this.$router.push({ path: "/recode/list" });
      });
    },

    updateInternship() {
      recodeApi.addInternship(this.internship).then((response) => {
        //提示信息
        this.$message({
          type: "success",
          message: "更新成功!",
        });
        //回到列表页面 路由跳转
        this.$router.push({ path: "/recode/list" });
      });
    },
  },
};
</script>

<style></style>
